<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
        <title></title>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">

         <!--app-->
        <link rel="stylesheet" href="css/fonts/font-awesome.min.css">
        <link rel="stylesheet" href="css/ui-box.css">
        <link rel="stylesheet" href="css/ui-base.css">
        <link rel="stylesheet" href="css/ui-color.css">
        <link rel="stylesheet" href="css/appcan.icon.css">
        <link rel="stylesheet" href="css/appcan.control.css">
        <link rel="stylesheet" href="css_sdk/css/main.css">
        <link rel="stylesheet" href="test_content/css/usearch.css">

        <style>
            .am-header-default {
                background-color: #eb1111;
            }
            .bc-btn {
                background-color: #eb1111;
            }
            .logo {
                background-image: url('images/logo.png');
            }
            .umhw1 {
                min-height: 9.16em;
                min-width: 13.5em;
            }
            
            .umar-a {
                margin: 1em;
            }
            .bc-head {
                background-color: #eb1111;
            }
            .sc-bg-active {
                background-color: #FFFFFF;
            }
            .bc-border-2 {
                border-color: #FFFFFF;
            }
            .lis-m {
                min-height: 2em;
            }
            .t-gra-85 {
            color: gray;
            }
            .text-red {
                color: #eb1111;
            }
            .sc-text-active {
                color: black !important;
                font-weight:  bold;
            }
            .bg-b{
                border-bottom: 2px #eb1111 solid;
            }
             .bc-top {
                background-color: #626262;
            }
             .bc-border {
                border-color: #626262;
            }
            
        </style>
        
        <script type="text/javascript" src="js/jquery-1.8.3.min.js"></script>
        <script type="text/javascript" src="js/moment.min.js"></script>
        <script type="text/javascript">
                var retData;
                var userRole=localStorage.getItem("role");
		var loginID=localStorage.getItem("user");
		var categoryID=sessionStorage.getItem("categoryID");
		var productCD=sessionStorage.getItem("productCD");
                
                var currStartDate=null;
                var currEndDate=null;
                var currCat=0;
            
                $(document).ready(function(){
			$.ajax({
				type: 'POST',
				async:false,
				url: "http://101.200.158.44:80/CosmeticSunyuxiWebService/services/CaigouManageWebService/OrderListInit" ,
				data: {"ID":loginID,"CategoryID":categoryID,"ProductCD":productCD},
				success: function(data){
					retData=data;
				},
				dataType: "json",
			});
			
                    var htm="<div id='cat0' class='ulev-1 ub ub-f1 ' data-index='0'> <div id='cat0cat' class='ub-f1 ub ub-ver item ub-ac sc-text-tab '><div class='ulev tx-c' onclick='activeCat("+0+")'>全部</div></div></div>";
				$.each(retData[0]["catList"],function(idx,item){
					var ht="<div id='cat"+item.f1+"' class='ulev-1 ub ub-f1' data-index='2'> <div id='cat"+item.f1+"cat' class='ub-f1 ub ub-ver item ub-ac sc-text-tab'> <div class='ulev tx-c t-gra-85' onclick='activeCat("+item.f1+")'>"+item.f2+"</div> </div> </div>";
					//商品分类列表List
					htm=htm+ht;
				})
			$("#cat").html(htm);
                        conCss(0);
                        document.getElementById("cat").style.display="none";
                        
                        dateConfig();
                        
                        changeDate(0);
                        /*
                        $.ajax({
				type: 'POST',
				async:false,
				url: "http://101.200.158.44:80/CosmeticSunyuxiWebService/services/ZijinManageWebService/XiaoShouYeJiDetailSearch" ,
				data: {"strUserRole":loginID,"CategoryID":0,"userCD":loginID},
				success: function(data){
					retData=data;
				},
				dataType: "json",
			});
                        */
                        

		});
                
                function activeCat(catid){
                    currCat=catid;
			$.ajax({
				type: 'POST',
				async:false,
				url: "http://101.200.158.44:80/CosmeticSunyuxiWebService/services/CaigouManageWebService/OrderListInit" ,
				data: {"ID":loginID,"CategoryID":catid,"ProductCD":productCD,"txtStartDate":currStartDate,"txtEndDate":currEndDate},
				success: function(data){
                                    retData=data;
				},
				dataType: "json",
			});
			var htm="<div id='cat0' class='ulev-1 ub ub-f1 ' data-index='0'> <div id='cat0cat' class='ub-f1 ub ub-ver item ub-ac sc-text-tab '><div class='ulev tx-c' onclick='activeCat("+0+")'>全部</div></div></div>";

				$.each(retData[0]["catList"],function(idx,item){
					var ht="<div id='cat"+item.f1+"' class='ulev-1 ub ub-f1' data-index='2'> <div id='cat"+item.f1+"cat' class='ub-f1 ub ub-ver item ub-ac sc-text-tab'> <div class='ulev tx-c t-gra-85' onclick='activeCat("+item.f1+")'>"+item.f2+"</div> </div> </div>";
					//商品分类列表List
					htm=htm+ht;
				})
				$("#cat").html(htm);
			conCss(catid);
			
                        $.ajax({
				type: 'POST',
				async:false,
//				url: "http://101.200.158.44:80/CosmeticSunyuxiWebService/services/ZijinManageWebService/XiaoShouYeJiDetailSearch" ,
//				data: {"strUserRole":userRole,"CategoryID":categoryID,"userCD":loginID,"txtStartDate":currStartDate,"txtEndDate":currEndDate},
                                url: "http://101.200.158.44:80/CosmeticSunyuxiWebService/services/ZijinManageWebService/MoneyListSearch" ,
				data: {"ID":loginID,"txtStartDate":currStartDate,"txtEndDate":currEndDate},
				success: function(data){
                                     console.log(loginID);
                                    console.log(currStartDate);
                                     console.log(currEndDate);
					retData=data;
				},
				dataType: "json",
			});
                        
                        $("#cat").hide();
                        
                        genData();
		}
                
                function conCss(temp){
			var obj=document.getElementById("cat"+temp+"cat");
			obj.className=obj.className+' sc-text-active';

			var obj1=document.getElementById("cat"+temp+"");
			obj1.className=obj1.className+' bg-b';

		}
                
            function dateConfig(){
                //日期处理
                var year=new Date().getFullYear();
                var da= da=moment().format('YYYY-MM');
                var arrayNation = new Array(); 
                var start=moment().format('YYYY-MM');
                for(var i=0;i<13;i++){
                    arrayNation.push(moment().subtract(i, 'month').format('YYYY-MM'));
                }
                
                
                
                //var _select = document.createElement("select");  
                //var firstOption = document.createElement("option");  
                //firstOption.value = "";  
                //firstOption.text = "下单时间";  
                //_select.appendChild(firstOption); 
                
                for ( i = 0; i < arrayNation.length; i++){  
                    var _option = document.createElement("option");  
                    _option.value = arrayNation[i];  
                    _option.text = arrayNation[i];  
                    if (da == arrayNation[i]){  
                        _option.selected = "true";  
                    }  
                    document.getElementById("op").appendChild(_option);  
                }
                
               
            }
            
            function changeDate(val){
                if(val==0){
                    var year=new Date().getFullYear();
                    currStartDate=year+"-"+(new Date().getMonth()+1)+"-01 00:00:00";
                    currEndDate=year + '-' + (parseInt(new Date().getMonth())+1) + '-' + new Date(year,new Date().getMonth()+1,0).getDate()+" 23:59:59";
                }else{
                    var d=val.split("-");
                    currStartDate=d[0]+"-"+d[1]+"-01 00:00:00";
                    currEndDate=d[0] + '-' + d[1] + '-' + new Date(d[0],d[1],0).getDate()+" 23:59:59";
                }
                 activeCat(currCat);
            }
            
            function genData(){
                var m = new Map();
                var total=0;
                
                $.each(retData[0]["MoneyList"],function(idx,item){
                    var key = item['f5'].substr(0, 10);
                    var value=item['f3']+"#"+item['f2']+"#"+item['f4']+"=";
                    value=m.get(key)==undefined?value:m.get(key)+value;
                    m.put(key,value);
                });
                var htm1='<div class="ub ub-ver c-wh  uinn-a7" style="margin-top: 0.2em"><ul>'+
                    '<li class=" ub bc-border bc-text ub-ac lis-m" data-index="0">'+
                    '<div class="lv_title  marg-l ub-f1 ub-ver ut-m  ulev-1 t-gra-85" >时间</div>'+
                    '<div class="lv_title ub-f1 marg-l ub ub-ver ut-m line1 ulev-1 text-red" style="text-align: right" >￥lirun</div>'+
                    '</li>';
                
                var htm2='<li class=" ub bc-border bc-text ub-ac lis-m" data-index="0">'+
                    '<div class="lv_title  marg-l ub ub-ver ut-m line1 ulev-1 " style="width:45%">会员名</div>'+
                    '<div class="lv_title ub-f1 marg-l ub ub-ver ut-m line1 ulev-1" style="width:20%" >等级名</div>'+
                    '<div class="lv_title ub-f1 marg-l ub ub-ver ut-m line1 ulev-1" style="text-align: right">￥利润</div>'+
                    '</li>';
                
                var htm3='</ul>'+'</div>';
                
                var htmcode=""
                var htm="";
                var now=new Date()
                var date=31;
                //var year=new Date().getFullYear();
                var da=document.getElementById("op").value;

               
                var year = now.getFullYear();  
                for(date;date>0;date--){
                    var key="";
                    if(date<10){
                        var key=da+"-0"+date;
                    }else{
                        var key=da+"-"+date;
                    }
                    var value=m.get(key);
                    if(value==undefined){
                        continue;
                    }
                    
                    var total0=0;
                    var arr0= new Array();
                    arr0=value.split("=");
                    for(var i=0;i<arr0.length;i++){
                        var arr1=new Array();
                        arr1=arr0[i].split("#");
                        var uname=arr1[0];
                        var levelname=arr1[1];
                        var g=arr1[2];
                        if(g==undefined){
                            break;
                        }
                        total0=parseFloat(total0)+parseFloat(g);
                        htm=htm+htm2.replace("会员名",uname).replace("等级名",levelname).replace("利润",g);
                        
                    }
                    total=parseFloat(total)+parseFloat(total0);
                     htmcode=htmcode+htm1.replace("时间",key).replace("lirun",total0)+htm+htm3;
                }
//alert(m.get("2015-12-08"));
//                 m.each(function(key,value,index){
//                     alert(key);
//                     alert(value);
//                     var total0=0;
//                    var arr0= new Array();
//                    arr0=value.split("=");
//                    for(var i=0;i<arr0.length;i++){
//                        var arr1=new Array();
//                        arr1=arr0[i].split("#");
//                        var uname=arr1[0];
//                        var levelname=arr1[1];
//                        var g=arr1[2];
//                        if(g==undefined){
//                            break;
//                        }
//                        total0=parseFloat(total0)+parseFloat(g);
//                        htm=htm+htm2.replace("会员名",uname).replace("等级名",levelname).replace("利润",g);
//                        
//                    }
//                    total=parseFloat(total)+parseFloat(total0);
//                     htmcode=htmcode+htm1.replace("时间",key).replace("lirun",total0)+htm+htm3;
//                });
               $("#list").html(htmcode);
               $("#total").html("￥"+total);
            }
            
            
            Array.prototype.remove = function(s) {     
    for (var i = 0; i < this.length; i++) {     
        if (s == this[i])     
            this.splice(i, 1);     
    }     
}     
    
function Map() {     
    /** 存放键的数组(遍历用到) */    
    this.keys = new Array();     
    /** 存放数据 */    
    this.data = new Object();     
         
    /**   
     * 放入一个键值对   
     * @param {String} key   
     * @param {Object} value   
     */    
    this.put = function(key, value) {     
        if(this.data[key] == null){     
            this.keys.push(key);     
        }     
        this.data[key] = value;     
    };     
         
    /**   
     * 获取某键对应的值   
     * @param {String} key   
     * @return {Object} value   
     */    
    this.get = function(key) {     
        return this.data[key];     
    };     
         
    /**   
     * 删除一个键值对   
     * @param {String} key   
     */    
    this.remove = function(key) {     
        this.keys.remove(key);     
        this.data[key] = null;     
    };     
         
    /**   
     * 遍历Map,执行处理函数   
     *    
     * @param {Function} 回调函数 function(key,value,index){..}   
     */    
    this.each = function(fn){     
        if(typeof fn != 'function'){     
            return;     
        }     
        var len = this.keys.length;     
        for(var i=0;i<len;i++){     
            var k = this.keys[i];     
            fn(k,this.data[k],i);     
        }     
    };     
         
    /**   
     * 获取键值数组(类似Java的entrySet())   
     * @return 键值对象{key,value}的数组   
     */    
    this.entrys = function() {     
        var len = this.keys.length;     
        var entrys = new Array(len);     
        for (var i = 0; i < len; i++) {     
            entrys[i] = {     
                key : this.keys[i],     
                value : this.data[i]     
            };     
        }     
        return entrys;     
    };     
         
    /**   
     * 判断Map是否为空   
     */    
    this.isEmpty = function() {     
        return this.keys.length == 0;     
    };     
         
    /**   
     * 获取键值对数量   
     */    
    this.size = function(){     
        return this.keys.length;     
    };     
         
    /**   
     * 重写toString    
     */    
    this.toString = function(){     
        var s = "{";     
        for(var i=0;i<this.keys.length;i++,s+=','){     
            var k = this.keys[i];     
            s += k+"="+this.data[k];     
        }     
        s+="}";     
        return s;     
    };     
}     
            
        </script>
</head>


<body class="um-vp bc-bg" >

        <div id="page_0" class="up ub ub-ver" tabindex="0">
            
         <div id="header" class="uh bc-text-head ub bc-head">
               <div class="nav-btn" id="nav-left" onclick="javascript:history.go(-1)">
                    <div class="fa fa-angle-left fa-2x"></div>
                </div>
                <h1 class="ut ub-f1 ulev-3 ut-s tx-c" tabindex="0">我的资金</h1>
                <div class="nav-btn nav-bt" id="nav-right"></div>
        </div>
            
            
         <div class="uf t-bla ub tab_l bc-top">
           <div class="ulev-1 ub ub-f1  ub-ac ub-pc">
               <div id="datetime">
                   <select id="op" onchange="changeDate(this.value)"></select>
               </div>
           </div>   
       </div>    
            
     <div id="cat" class="uf t-bla tab_l " style=" background-color: white">    
       </div>

            
        <div class="ub ub-ver c-wh  uinn-a7" >
            <ul>
                <li class=" ub bc-border bc-text ub-ac lis-m" data-index="0">
                    <div class="lv_title  marg-l ub-f1 ub-ver ut-m  ulev-1" style="font-weight:bold">累计利润收益(元)</div>
                    <div class="lv_title ub-f1 marg-l ub ub-ver ut-m line1 ulev-1 text-red" style="text-align: right" id="total">￥10000.00</div>
                    
                </li>
            </ul>
        </div>    
            
            <div id="list">
            </div>
           <!-- 
        <div class="ub ub-ver c-wh  uinn-a7" style="margin-top: 0.2em">
            <ul>
                
                <li class=" ub bc-border bc-text ub-ac lis-m" data-index="0">
                    <div class="lv_title  marg-l ub-f1 ub-ver ut-m  ulev-1 t-gra-85" >2015-11-13</div>
                    <div class="lv_title ub-f1 marg-l ub ub-ver ut-m line1 ulev-1 text-red" style="text-align: right" >￥4000.00</div>
                    
                </li>
                <li class=" ub bc-border bc-text ub-ac lis-m" data-index="0">
                    <div class="lv_title  marg-l ub ub-ver ut-m line1 ulev-1 " style="width:20%">A加盟店</div>
                    <div class="lv_title ub-f1 marg-l ub ub-ver ut-m line1 ulev-1" style="width:50%" >SDJJ001张三</div>
                    <div class="lv_title ub-f1 marg-l ub ub-ver ut-m line1 ulev-1" style="text-align: right">￥200</div>
                </li>
                <li class=" ub bc-border bc-text ub-ac lis-m" data-index="0">
                    <div class="lv_title  marg-l ub ub-ver ut-m line1 ulev-1 " style="width:20%">A加盟店</div>
                    <div class="lv_title ub-f1 marg-l ub ub-ver ut-m line1 ulev-1" style="width:50%" >SDJJ001张三</div>
                    <div class="lv_title ub-f1 marg-l ub ub-ver ut-m line1 ulev-1" style="text-align: right">￥200</div>
                </li>
            </ul>
        </div>
            <div class="ub ub-ver c-wh  uinn-a7" style="margin-top: 0.2em">
            <ul>
                
                <li class=" ub bc-border bc-text ub-ac lis-m" data-index="0">
                    <div class="lv_title  marg-l ub-f1 ub-ver ut-m  ulev-1 t-gra-85" >2015-11-13</div>
                    <div class="lv_title ub-f1 marg-l ub ub-ver ut-m line1 ulev-1 text-red" style="text-align: right" >￥4000.00</div>
                    
                </li>
                <li class=" ub bc-border bc-text ub-ac lis-m" data-index="0">
                    <div class="lv_title  marg-l ub ub-ver ut-m line1 ulev-1 " style="width:20%">A加盟店</div>
                    <div class="lv_title ub-f1 marg-l ub ub-ver ut-m line1 ulev-1" style="width:50%" >SDJJ001张三</div>
                    <div class="lv_title ub-f1 marg-l ub ub-ver ut-m line1 ulev-1" style="text-align: right">￥200</div>
                </li>
                <li class=" ub bc-border bc-text ub-ac lis-m" data-index="0">
                    <div class="lv_title  marg-l ub ub-ver ut-m line1 ulev-1 " style="width:20%">A加盟店</div>
                    <div class="lv_title ub-f1 marg-l ub ub-ver ut-m line1 ulev-1" style="width:50%" >SDJJ001张三</div>
                    <div class="lv_title ub-f1 marg-l ub ub-ver ut-m line1 ulev-1" style="text-align: right">￥200</div>
                </li>
            </ul>
        </div>
-->
        </div>
    <script src="js/appcan.js"></script>
    <script src="js/appcan.control.js"></script>
    <script src="js/appcan.tab.js"></script>
    <script>
        function click_sub(){
            window.location.href="home.html";
        }
        
//         var tabview = appcan.tab({
//            selector : "#tabview",
//            hasIcon : false,
//            hasAnim : true,
//            hasLabel : true,
//            hasBadge : false,
//            data : [{
//                label : "全部分类",
//            }, {
//                label : "面膜",
//            }, {
//                label : "面膜",
//            }, {
//                label : "面膜",
//            }]
//        });
//        tabview.on("click", function(obj, index) {
//            //appcan.window.selectMultiPopover("content", index);
//        })
    </script>

</body>
</html>
